<template>
  <div>
    <van-nav-bar :title="comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'">
      <van-icon slot="left"
                name="cross"
                @click="$emit('close')" />
    </van-nav-bar>
    <div class="scroll-wrap">
      <comment-item :comment="comment"></comment-item>
      <van-cell title="全部回复" />
      <comment-list :source="comment.com_id"
                    :type="'c'"
                    :list="list"
                    @reply-click="$emit('reply-click', $event)"></comment-list>
    </div>

    <div class="post-wrap">
      <van-button size="small"
                  round
                  class="post-btn"
                  @click="replyShow = true">写回复</van-button>
    </div>

    <van-popup v-model="replyShow"
               position="bottom">
      <comment-post :target="comment.com_id"
                    @post-success="postReply"></comment-post>
    </van-popup>
  </div>
</template>

<script>
import CommentList from '../comment-list'
import CommentItem from '../comment-item'
import CommentPost from '../comment-post'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  // created () {
  //   console.log(this.comment)
  // },
  data () {
    return {
      replyShow: false,
      list: []
    }
  },
  methods: {
    postReply (value) {
      this.replyShow = false
      this.list.unshift(value.new_obj)
    }
  }
}
</script>

<style lang="less" scoped>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  height: 88px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
